/**
 * 获取统一框架接口组织机构角色的信息
 */
 
 
var re=null;
Ext.onReady(function(){
     Ext.QuickTips.init();
     Ext.state.Manager.setProvider(new Ext.state.CookieProvider());
    var  url = '?className=cn.com.jsepc.rep.comm.LocalPurview';  
     //设置checkbox是否多选 false:否,true:是
     var org_root =new Ext.tree.AsyncTreeNode({text:'',id:'-1'});
     var orgrole_tree=new Ext.tree.TreePanel(
     {
        id:'orgrole_tree',
        frame : true,
        loader: new Ext.tree.TreeLoader(
        {
             baseAttrs : {
                uiProvider : Ext.tree.TreeCheckNodeUI
             }
        }
        ),
        rootVisible:false,
        width : '50%',
        height : 400,
        //title:'角色授权',
        lines:false,
        autoScroll:true,
        animate:false,
        frame:false,
        region:'center',
        root:org_root,
        iconCls : 'nav',
         // multiple// 对树的级联多选
        onlyLeafCheckable : true,// 对树所有结点都可选
        checkModel:'single',
        tbar : ['-',
        	{
        		text:'角色授权',
        		id:'btnshowwin',
        		iconCls :'section',
        		//handler:showmodalwin
        		handler : function() {
        			if(!isValidate())return;
   					var node=Ext.getCmp('orgrole_tree').getChecked()[0];
   					var roleid=node.attributes.id.split(",")[1];
   					//alert(roleid);
   					window.showModalDialog("../role_Competence1/role_Competencel.jsp?roleid="+roleid, '','dialogWidth=900px;dialogHeight=600px;status:no;resizable:yes;');	   
        		}
        	}
//        	,'-',
//        	{
//        		text:'同步用户数据权限',
//        		id:'btnSyncUserPurview',
//        		iconCls :'section',
//        		handler:syncUserPurview
//        	}
//			,'-',{
//        		text:'同步差异数据权限',
//        		id:'btnSyncDif',
//        		iconCls :'section',
//        		handler:syncUserDif
//        	}
//        	,'-',{
//        		text:'数据权限',
//        		id:'btndatapurview',
//        		iconCls :'section',
//        		handler:showdatapurview
//        	}
        ]
    });
    //--------组织机构用户树------------
   		orgrole_tree.on('click',function (node,e){ 
	        Ext.mytree.resetBoldNodes(orgrole_tree.getRootNode());
	        node.getUI().addClass('selitem');
        
	  	});
        orgrole_tree.on('beforeload', function(node, e) {
                if (node.getDepth() == 0) { 
//                	 var rootNodes=rootNodesInfo.split(splitChar);
//					 for(var i=0;i<rootNodes.lenth;i++){
//					 	var s=rootNodes[i].split(",");
//					 	var cnode=new Ext.tree.TreeNode({
//					 		text:s[s.length-1],
//					 		id:rootNodes[i]
//					 	});
//					 	node.appendChild(cnode);
//					 }
                	 var openUrl = url+'&methodName=getOrg_Role&paramCount=2';
	                    openUrl += '&param_0=null&param_1='+encodeURIComponent(rootNodesInfo);
	                    node.loader = new Ext.tree.TreeLoader({   
	                    dataUrl :basePath+'JarpListener'+openUrl,
	                     baseAttrs : {
	                         uiProvider : Ext.tree.TreeCheckNodeUI
	                         }
                   		 });
        		
                }else
                {
                    var openUrl = url+'&methodName=getOrg_Role&paramCount=2';
                    openUrl += '&param_0='+node.id+'&param_1='+basePath;
                    node.loader = new Ext.tree.TreeLoader({   
                    dataUrl :basePath+'JarpListener'+openUrl,
                     baseAttrs : {
                         uiProvider : Ext.tree.TreeCheckNodeUI
                         }
                    });
                }
                
                
        });
        
        
        orgrole_tree.root.reload();
        var mainPanel=new Ext.Panel({
        	border:false,
        	layout:'border',
        	region:'center',
        	items:[
        		orgrole_tree
        	]
        	
        });
        var viewport = new Ext.Viewport({
            frame:true,
            layout:'border',
            items: [
                mainPanel
            ]
       });
       
       
       function isValidate()
       {
            re=Ext.getCmp('orgrole_tree').getChecked();
            if(re.length<=0)
            {
                 Ext.Msg.alert('提示', '请选择角色信息');  
                 return  false;
            }
            return true;
       }
       
 /*     var  modalwin=new Ext.Window({
       				title:'角色授权',
       				width:800,
       				height:600,
       				closeAction:'hide',
       				modal:true,
       				html:'<iframe id="localpurivewif" width="100%" frameborder="0" height="100%" src=""></iframe>',
       				border:true
       			});
       
       function showmodalwin(){
       		if(!isValidate())return;
   			var node=Ext.getCmp('orgrole_tree').getChecked()[0];
   			modalwin.show();
   			modalwin.setTitle("角色授权");
   			var roleid=node.attributes.id.split(",")[1];
   			//alert(roleid);
   			//alert(basePath);
   			document.getElementById("localpurivewif").setAttribute("src",basePath+'/role_Competence1/role_Competencel.jsp?roleid='+roleid);
       }*/
       
});